package com.morningstar.system.api.feign.fallback;

import com.morningstar.system.api.entity.SysUserFeign;
import com.morningstar.system.api.feign.ISystemUserFeign;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yls
 * @since 2023.06.17
 */
@Slf4j
@Component
public class SystemUserFeignFactory implements FallbackFactory<ISystemUserFeign> {

    @Override
    public ISystemUserFeign create(Throwable cause) {
        log.error("ISystemUserFeign {}", ExceptionUtils.getStackTrace(cause));
        return new SystemUserFeignFallback();
    }

    class SystemUserFeignFallback implements ISystemUserFeign {

        @Override
        public SysUserFeign getUserById(String userId) throws Exception {
            log.error("call system user feign fall back");
            return null;
        }

        @Override
        public SysUserFeign getUserByName(String userName) throws Exception {
            log.error("call system user feign fall back");
            return null;
        }

        @Override
        public SysUserFeign getUserByMobile(String mobile) throws Exception {
            log.error("call system user feign fall back");
            return null;
        }

        @Override
        public List<String> getPermissionList(String loginId, String loginType) {
            return new ArrayList<>();
        }

        @Override
        public List<String> getRoleList(String loginId, String loginType) {
            return new ArrayList<>();
        }

        @Override
        public List<Long> selectUserByIds(List<Long> ids) {
            return new ArrayList<>();
        }

        @Override
        public List<Long> selectUserByRoleIds(List<Long> ids) {
            return new ArrayList<>();
        }

        @Override
        public List<Long> selectUserByDeptIds(List<Long> ids) {
            return new ArrayList<>();
        }

        @Override
        public List<Long> selectUserByPostIds(List<Long> ids) {
            return new ArrayList<>();
        }

        @Override
        public List<Long> selectUserByDeptLeaderIds(List<Long> ids) {
            return new ArrayList<>();
        }

        @Override
        public Map<Long, String> selectUserIdAndName() {
            return new HashMap<>();
        }

        @Override
        public void userLoginSuccess(Long loginId, String ip) {

        }
    }
}
